package drawingtools;

import gui.DrawingPanel;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Vector;

import program.DatabaseConnection;

import utils.Point;
import diagramobjects.DiagramObjects;
import diagramobjects.ArrowsTextLine;

public class ManipulateTool extends DrawingTool { 
	
	private DiagramObjects DiagramObjs;
	//private Line tempLine;
	private DrawingPanel DrawPanel;
	private Integer FirstX;
	private Integer FirstY;
	
	public ManipulateTool(DiagramObjects go, DrawingPanel dp)
	{
		DiagramObjs = go;
		DrawPanel = dp;
	}
	
	@Override
	public void mouseClicked(MouseEvent arg0) 
	{
		/*//System.out.println("SelectionTool->mouseClicked()");
		//SelectionTool
		for (int i = 0; i < DiagramObjs.CountGeomObjs(); ++i)
		{
			if (DiagramObjs.GetGeometricbjectFromPanel(i).PointCollision(arg0.getX(), arg0.getY()))
			{
				//DrawPanel.CleanAllSelections();
				DrawPanel.changeSelection(i);
				System.out.println("DrawPanel -> ChangeSelection(" + i + ")");
				//DrawPanel.repaint();
				
			}
				
		}
		*/
		
		
	}



	@Override
	/**
	 * Reaguje na klikniecie na panelu, 
	 * jesli ClickCount = 0 - poczatek tworzenia
	 * 			dodaje linie do panelu, 
	 * 			odniesienie zapisuje pod tempLine - mozna przesuwac teraz tempLine
	 * 			dodaje tempLine do BD
	 * jesli cliccount == 1
	 * 			zeruje clickcount
	 */
	public void mousePressed(MouseEvent arg0) {
		super.mousePressed(arg0);
		System.out.println("mouseClicked, clickcount:" + ClickCount);
		FirstX = arg0.getX();
		FirstY = arg0.getY();
		


	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		super.mouseReleased(arg0);
		
		DrawPanel.repaint();
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		super.mouseDragged(e);
		Integer vx = e.getX() - FirstX;
		Integer vy = e.getY() - FirstY;
		FirstX = e.getX();
		FirstY = e.getY();
		for (int i = 0; i < DiagramObjs.GetSize(); ++i)
		{
			if (DrawPanel.getIfElementSelected(i) == 1)
				DiagramObjs.GetGeometricbjectFromPanel(i).MoveByVector(vx, vy);
		}
		
		System.out.println("SelectionTool -> MD)");
		DrawPanel.repaint();
	}

	/**
	 * W przypadku rysowania, gdy user przesunie wskaznik myszy przesuwa koniec 
	 * linii i zapisuje jej polozenie w pamieci
	 */
	

	

}
